package com.anket.poll;

import java.io.Serializable;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import org.primefaces.model.chart.PieChartModel;

import com.anket.option.model.Option;
import com.anket.poll.bo.PollBo;
import com.anket.poll.model.Poll;

@ManagedBean(name = "homePageBean")
@RequestScoped
public class HomePageBean implements Serializable {

	private PollBo pollBo;
	private Poll selectedPoll;
	private PieChartModel chartModel;
	private String str;
	
	
	public String getStr() {
		return "anket.xhtml";
	}

	public void setStr(String str) {
		this.str = str;
	}

	private int selectedPollId=-1;

	public Poll getSelectedPoll() {
		return selectedPoll;
	}

	public void setSelectedPoll(Poll selectedPoll) {
		this.selectedPoll = selectedPoll;
	}
	
	public PieChartModel getChartModel() {
		chartModel = new PieChartModel();
		if (selectedPoll != null)
			for (Option option : selectedPoll.getAllOptions()) {
				chartModel.set(option.content, option.click);
			}

		return chartModel;
	}

	public PollBo getPollBo() {
		return pollBo;
	}

	public void setPollBo(PollBo pollBo) {
		this.pollBo = pollBo;
	}

	public List<Poll> getAllPolls() {
		return pollBo.getAllPolls();
	}
	


}
